/**
 * 区域
 * @returns
 */
// $("#city").val(data.cityCode);
//$("#county").val(data.countyCode);
//$("#street").val(data.streetCode);

function getProvinceList(province,city,county,street){
	$.ajax({
		url: "/area/getProvinceList",
		type: 'GET',
		async:false,
		success: function(d){
			var success = d.success;
			if(success==true){
				if(d.data!=null){
					var result ='';
					var code="";
					$.each(d.data,function(i,item){
						if(i==0){
							code=item.code;
						}
						result+='<option value="'+item.code+'">'+item.name+'</option>';	
					})
					if(city!=null){
						code=city;
					}
					$("#province").html(result);
					if(province!=null&&province!=''){
						$("#province").val(province);
					}
					getCityList(code,city,county,street);
				}	 
			}
		}
	})
}

//加载一个省下的市  code为省的code
function getCityList(code,city,county,street){
console.log(code,city,county,street);
	var url = "/area/getChildList/";
	if(city!=null){
		url ="/area/getSiblingListByCode/";
	}
	$.ajax({
		url: url+code,
		type: 'GET',
		async:false,
		success: function(d){
			var success = d.success;
			if(success==true){
				if(d.data!=null){
					var result ='';
					var code="";
					$.each(d.data,function(i,item){
						if(i==0){
							code=item.code;
						}
						result+='<option value="'+item.code+'">'+item.name+'</option>';	
					})
					if(county!=null){
						code=county;
					}
					$("#city").html(result);
					if(city!=null&&city!=''){
						$("#city").val(city);
					}
					getCountyList(code,county,street);
				}	 
			}
		}
	})
}

//加载一个市下的区县 code为市的code
function getCountyList(code,county,street){
	var url = "/area/getChildList/";
	if(county!=null){
		url ="/area/getSiblingListByCode/";
	}
	$.ajax({
		url: url+code,
		type: 'GET',
		async:false,
		success: function(d){
			var success = d.success;
			if(success==true){
				if(d.data!=null){
					var result ='';
					var code="";
					$.each(d.data,function(i,item){
						if(i==0){
							code=item.code;
						}
						result+='<option value="'+item.code+'">'+item.name+'</option>';	
					})
					if(street!=null){
						code= street;
					}
					$("#county").html(result);
					if(county!=null&&county!=''){
						$("#county").val(county);
					}
					getStreetList(code,street);
				}	 
			}
		}
	})
}


//加载一个市下的区县
function getStreetList(code,street){
//	console.log(code,street);
	var url = "/area/getChildList/";
	if(street!=null){
		url ="/area/getSiblingListByCode/";
	}
	$.ajax({
		url: url+code,
		type: 'GET',
		async:false,
		success: function(d){
			var success = d.success;
			if(success==true){
				if(d.data!=null){
					var result ='';
					var code="";
					$.each(d.data,function(i,item){
						if(i==0){
							code=item.code;
						}
						result+='<option value="'+item.code+'">'+item.name+'</option>';	
					})
					$("#street").html(result);
					if(street!=null&&street!=''){
						$("#street").val(street);
					}
				}	 
			}
		}
	})
}


function provinceChange(value){
	var pid = $("#province").val();
	getCityList(pid,null,null,null);
}

function cityChange(value){
	var pid = $("#city").val();
	getCountyList(pid,null,null);
}

function countyChange(value){
	var pid = $("#county").val();
	getStreetList(pid,null);
}